<?php

/*

Updates (updates.php)

*/

$page_title = "Updates";
$rank_check = 0;
include "header.inc.php";
$game=$_GET['game'];
$findLimit = fetch("SELECT entry_limit FROM page_limits WHERE page = 'updates' AND game = '$game'");

if (!$findLimit[entry_limit]) { $findLimit[entry_limit] = "10"; }

mysql_query("UPDATE members2 SET viewed_update=1 WHERE id = '$userid' AND game = '$game'");

if ($rank == 7) { $ifAdmin2 = "<p><b>Admins:</b> You may add an update by clicking <a href=admin/admin_add_update.php?game=$game>here</a>.</p>"; }

print "$openHTML";

if (!$start) { $start = 0; }

	$findPage = fetch("SELECT * FROM game_pages WHERE page_title = '$page_title' AND game = '$game'");
	if (!$findPage[id])
	{
		print "<p>Every time we make a change to our site we like to add an update to let you all know what's happening, so be sure to check back here often to catch up on the latest $gameName2 news. The homepage also lists the 3 most recent updates!</p>";
	}
	else
	{
		include "showpage.inc.php";
		print "$findPage[page_info]";
	}
	print "$ifAdmin2<Center>";

$findUpdates = mysql_query("SELECT * FROM updates2 WHERE game = '$game' ORDER BY timestamp DESC LIMIT $start,$findLimit[entry_limit]");
$numupdates = mysql_num_rows(mysql_query("SELECT id FROM updates2 WHERE game = '$game'"));

$x = 0;
while ($getUpdates = mysql_fetch_array($findUpdates))
{
	if ($rank == 7) { $ifAdmin = "<br><A HREF=\"javascript:;\" 	onclick=\"if ( !confirm ('Are you sure you want to delete this update?') ) { return false; } window.open('$baseurl/admin/admin_delete_update.php?game=$game&id=$getUpdates[id]','deleteupdate',config='height=150,width=225,menubar=no,resizable=yes,directories=no,scrollbars=yes,status=yes,toolbar=no'); 	return false;\">Delete this update!</a>"; }

	$written = date("M jS, Y", $getUpdates[timestamp]);

	if ($written != "$written2")
	{
		$updates .= "<p align=center><br><font size=+1><B>Updates for $written:</b></font></p>";
	}

	if (!$getUpdates[subject]) { $getUpdates[subject] = "<i>No subject for this update.</i>"; }
	$updates .= "
	<p><B>$getUpdates[subject]</b> - <font size=-1><a href=user_profile.php?user=$author[username]&game=$game>$author[display_name]</a><Br>
	<font size=-1>$getUpdates[message]$ifAdmin</font></P>";

	$written2 = $written;
	$x++;

}

print "<table><tr><td>$updates</td></tr></table>";

print "<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=400>
   <TR>
      <TD COLSPAN=5 BGCOLOR=\"$topAndBottomBG\">
         <P><FONT SIZE=\"-1\" COLOR=\"$topAndBottomText\"><B>Older
         Updates:</B></FONT></P>
      </TD>
   </TR>";

$pages = ceil($numupdates/$findLimit[entry_limit]);
$y = 0;
$x = 1;
$z = 0;
$start2 = 1;
$end2 = $findLimit[entry_limit];
while ($x <= $pages)
{
	if ($z == "0")
	{
		$pageList .= "<tr>";
	}
	if ((($start + 1) >= $start2) AND (($start + 1) <= $end2)) { $updateCellColor = "$middleBG"; } else { $updateCellColor = "FFFFFF"; }
	$pageList .= "<TD
BGCOLOR=\"$updateCellColor\"> <CENTER><B><a
href=updates.php?game=$game&start=$y><FONT SIZE=\"-1\">$start2 - $end2</FONT></a></B></CENTER> </TD>";
	$z++;
	if ($z == "5")
	{
		$pageList .= "</tr>";
		$z = 0;
	}
	$y = $y + $findLimit[entry_limit];
	$x++;
	$start2 += $findLimit[entry_limit];
	$end2 += $findLimit[entry_limit];
}

print "$pageList</TABLE></CENTER>";

print "$closeHTML";
?>